import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'personalBWdetailM',

  state: {
    dicMap: undefined,
  },

  effects: {
    //获取黑白名单
    *getBWList({ payload, callback }, { call, put }) {
      const response = yield call(api.agencyTask.approvalList.getBWList, payload);
      // const response ={"data":{"dataSource":[{"id":"28bfc141747784a901747abca29f0038","pid":null,"shortName":"ww","longName":"www","portfolioName":"查询组合下钻产品明细（组合由多个组合构成）","portfolioId":"62","creator":"administrator","createTime":"2021-01-08","status":null}],"pageInfo":{"total":1,"currentPage":2,"numInPage":20},"columns":[{"key":"shortName","title":"交易对手短名"},{"key":"longName","title":"交易对手长名"}]},"code":"0","msg":null}
      if (response) {
        if (response.code == 0) {
          callback('success', response.data || {});
        } else {
          callback('fail');
          message.error(response.msg || '查询交易对手信息失败!');
        }
      } else {
        callback('fail');
        message.error('查询交易对手信息失败!');
      }
    },
    //修改黑白名单
    *updateBWlist({ payload, callback }, { call, put }) {
      const response = yield call(api.agencyTask.approvalList.updateBWlist, payload);
      // const response={
      //   code:0,
      //   msg:null
      // }
      if (response) {
        if (response.code == 0) {
          callback('success');
        } else {
          callback('fail');
          message.error(response.msg || '保存失败!');
        }
      } else {
        callback('fail');
        message.error('保存失败!');
      }
    },
    //查询短名
    *getShortName({ payload, callback }, { call, put, select }) {
      const res = yield call(api.personnelManagement.getShortName, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback([]);
        message.error('查询短名失败!');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
